﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

class BinaryToHexadecimal
{
    static void Main(string[] args)
    {
        string binaryNumber = "101011010001011111";
                        //"0010 1011 0100 0101 1111"
        Console.WriteLine(HexadecimalGenerator(binaryNumber));
    }

    private static string HexadecimalGenerator(string binaryNumber)
    {
        if (binaryNumber.Length % 4 != 0)
        {
            binaryNumber = binaryNumber.PadLeft(4*(binaryNumber.Length / 4) + 4,'0');
        }

        string result = "";
        
        for (int i = 0; i < binaryNumber.Length; i += 4)
        {
            string quaternion;

            quaternion = binaryNumber.Substring(i, 4);

            result += string.Format("{0:X}", Convert.ToByte(quaternion, 2));
        }
        return result;
    }
}